import 'package:flutter/material.dart';
import 'package:flutter_app01/config/Config.dart';

// 订单详情页
class OrderDetailPage extends StatefulWidget {
  final Map arguments;
  OrderDetailPage({this.arguments});

  @override
  State<StatefulWidget> createState() => OrderDetailState(orderInfo: arguments['orderInfo']);
}

class OrderDetailState extends State {
  final Map orderInfo;
  OrderDetailState({this.orderInfo});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('订单详情')),
        body: Container(
          color: Color.fromRGBO(200, 200, 200, 0.2),
          padding: EdgeInsets.all(10),
          child: ListView(
            children: [
              // 地址
              Container(
                color: Colors.white,
                padding: EdgeInsets.only(top: 10, bottom: 10),
                child: ListTile(
                    leading: Icon(Icons.add_location),
                    title: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text('${orderInfo['name']}  ${orderInfo['phone']}'),
                        Text('${orderInfo['address']}'),
                      ],
                    )),
              ),
              SizedBox(height: 10),

              // 订单
              Container(
                color: Colors.white,
                child: ListView.builder(
                    shrinkWrap: true,
                    itemCount: orderInfo['order_item'].length,
                    itemBuilder: (context, index) {
                      var item = orderInfo['order_item'][index];

                      String pic = item['product_img'];
                      return Column(
                        children: [
                          ListTile(
                            leading: Image.network(
                                '${Config.domain + pic.replaceAll(RegExp(r'\\'), '/')}'),
                            title: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                    '${item['product_title']}',
                                    maxLines: 2,
                                    overflow: TextOverflow.ellipsis,
                                    style: TextStyle(
                                        fontSize: 14, color: Colors.black54)),
                                SizedBox(height: 10),
                                Text('${item['selected_attr']}',
                                    style: TextStyle(
                                        fontSize: 14, color: Colors.black54)),
                                SizedBox(height: 10),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text('￥${item['product_price']}',
                                        style: TextStyle(
                                          fontSize: 14,
                                          color: Colors.red,
                                        )),
                                    Text('x ${item['product_count']}',
                                        style: TextStyle(
                                          fontSize: 14,
                                        ))
                                  ],
                                )
                              ],
                            ),
                          ),
                          index == 1 ? Container(height: 0) : Divider(),
                        ],
                      );
                    }),
              ),
              SizedBox(height: 10),

              // 订单编号等
              Container(
                color: Colors.white,
                child: Column(
                  children: [
                    Container(
                      padding: EdgeInsets.all(20),
                      child: Row(
                        children: [
                          Text('订单编号：',style: TextStyle(
                            fontWeight: FontWeight.w900,
                          )),
                          Expanded(
                            flex: 1,
                            child: Text(
                              '${orderInfo['order_item'][0]['order_id']}',
                                maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.all(20),
                      child: Row(
                        children: [
                          Text('下单日期：',style: TextStyle(
                            fontWeight: FontWeight.w900,
                          )),
                          Text(
                            '${orderInfo['order_item'][0]['add_time']}',
                          ),
                        ],
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.all(20),
                      child: Row(
                        children: [
                          Text('支付方式：',style: TextStyle(
                            fontWeight: FontWeight.w900,
                          )),
                          Text('${orderInfo['pay_status']}'),
                        ],
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.all(20),
                      child: Row(
                        children: [
                          Text('配送方式：',style: TextStyle(
                            fontWeight: FontWeight.w900,
                          )),
                          Text('顺丰'),
                        ],
                      ),
                    ),


                  ],
                ),
              ),
              SizedBox(height: 10),

              Container(
                padding: EdgeInsets.all(20),
                color: Colors.white,
                child: Row(
                  children: [
                    Text('总金额：',style: TextStyle(
                      fontWeight: FontWeight.w900,
                    )),
                    Text('￥${orderInfo['all_price']}元',style: TextStyle(
                      color: Colors.red,
                    )),
                  ],
                ),
              ),
            ],
          ),
        ));
  }
}
